//
//  HSMessageTableViewCell.swift
//  SchoolDemo
//
//  Created by rimi on 16/10/10.
//  Copyright © 2016年 YQ. All rights reserved.
//

import UIKit

///用于回调点赞和回复按钮的事件闭包类型
typealias CellBtncallback = (_ cell:UITableViewCell) -> ()

class HSMessageTableViewCell: UITableViewCell {

    @IBOutlet weak var messageIconV: UIImageView!

    @IBOutlet weak var messageUserNameL: UILabel!
    
    @IBOutlet weak var messageUserType: UILabel!
    
    @IBOutlet weak var messageDateL: UILabel!
    
    @IBOutlet weak var messageTitleL: UILabel!
        
    @IBOutlet weak var messageContentL: UILabel!
    
    @IBOutlet weak var messageLikeBtn: UIButton!
    //回复背景视图（使用了自定义类型）
    @IBOutlet weak var messageReplayBgV: HSReplayView!
    
    @IBOutlet weak var messageReplayViewH: NSLayoutConstraint!
    //点赞按钮回调闭包
    var likeBtnCallback: CellBtncallback?
    //回复按钮回调闭包
    var replauBtnCallback: CellBtncallback?
    
    //数据模型（消息视图模型）
    var messageVM: HSMessageViewModal? {
        didSet {
            //拼接头像地址
            let iconImageUrl = "http://120.24.57.38/new/zao/" + (messageVM?.message.not_tpath ?? "")
        
            messageIconV.xx_setImage(urlStr: iconImageUrl, placeholderImage: "boy", size: CGSize(width: 50, height: 50))
            

            messageUserNameL.text = messageVM?.message.not_Name
            messageUserType.text = messageVM?.message.not_courseName
            messageDateL.text = messageVM?.message.not_createDate
            messageTitleL.text = messageVM?.message.not_title
            messageContentL.text = messageVM?.message.not_content
            //设置点赞按钮
            let liken = messageVM?.message.likenum ?? 0
            if liken > 0 {
                messageLikeBtn.setTitle("\(liken)", for: .selected)
                messageLikeBtn.isSelected = true
                
            } else {
                messageLikeBtn.isSelected = false
            }
            //传递模型给回复视图
            messageReplayBgV.messageVM = messageVM
            //设置高度
            messageReplayViewH.constant = messageVM?.replayViewH ?? 0
        }
    }
    
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        //设置圆角
//        messageIconV.layer.cornerRadius = 25
//        messageIconV.layer.masksToBounds = true
        //设置用户类型边框
        messageUserType.layer.cornerRadius = 8
        messageUserType.layer.borderWidth = 1
        messageUserType.layer.backgroundColor = UIColor().colorWithHex(0x00a0e9).cgColor
    }

    @IBAction func messageLikeBtnClicked(_ sender: UIButton) {
        
        likeBtnCallback?(self)
    }
    
    
    @IBAction func messageReplayBtnClicked(_ sender: AnyObject) {
        
        replauBtnCallback?(self)
    }
    
    
}
